package com.kate.mall.bff.wx.controller;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2020-11-25 15:31
 */
@Configuration
public class MyRedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean
    public RedissonClient getRedisson() {

        Config config = new Config();
        //TODO 1.单机模式
        //#####可以写上 rediss:// 来启用ssl连接#######
        config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password);
        //TODO 2.主从模式配置
        //config.useMasterSlaveServers()
        //        // use "rediss://" for SSL connection
        //        .setMasterAddress("redis://127.0.0.1:6379")
        //        .addSlaveAddress("redis://127.0.0.1:6389", "redis://127.0.0.1:6332", "redis://127.0.0.1:6419")
        //        .addSlaveAddress("redis://127.0.0.1:6399");
        //TODO 3.集群模式配置
        //config.useClusterServers()
        //        .setScanInterval(2000) // 集群状态扫描间隔时间，单位是毫秒
        //        //可以用"rediss://"来启用SSL连接
        //        .addNodeAddress("redis://127.0.0.1:7000", "redis://127.0.0.1:7001")
        //        .addNodeAddress("redis://127.0.0.1:7002");
        return Redisson.create(config);
    }
}